/**
 * 添加用户交易
 * @author alern2008@gmail.com
 * @系统名称：定制化辅助生成制造系统
 */

package org.ccams.tran;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.ccams.domain.TClient;

public class Tran11112 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// 获得用户录入信息
		//客户信息头
          String accountcode     =(String) request.getParameter("accountcode"); //客户编码  
          String accountname     =(String) request.getParameter("accountname"); //客户名称
          String corporator      =(String) request.getParameter("corporator"); //法人名称  
          String linkertel       =(String) request.getParameter("linkertel");//联系电话
//企业信息
          String customercode    =(String) request.getParameter("customercode"); //组织代码  
          String customername    =(String) request.getParameter("customername"); //组织名称  
          String corporatorcode  =(String) request.getParameter("corporatorcode");//法人身份证
	      String addresscop      =(String) request.getParameter("addresscop");    //公司地址 
	      String addresssale     =(String) request.getParameter("addresssale");   // 销售地址
	      String addressstock    =(String) request.getParameter("addressstock"); //仓库地址  
	      String addresstran     =(String) request.getParameter("addresstran"); // 发货地址  
	      String linker          =(String) request.getParameter("linker");   // 联系人      
	      String linkermobile    =(String) request.getParameter("linkermobile"); //联系人手机   
	      String linkerfax       =(String) request.getParameter("linkerfax");  //联系人传真     
	      String email           =(String) request.getParameter("email");   //email 
	      String product         =(String) request.getParameter("product"); //现经营产品   		     
	      String creevaluate     =(String) request.getParameter("creevaluate"); //信誉评估  		     
	      String kind            =(String) request.getParameter("kind");    // 企业性质
	      String regmoney        =(String) request.getParameter("regmoney"); //注册资本
	      String scope           =(String) request.getParameter("scope"); // 企业规模		     
//财务信息
	      String taxno           =(String) request.getParameter("taxno");  //税号
	      String accno           =(String) request.getParameter("accno");  //银行帐号	     
	      String bno             =(String) request.getParameter("bno");   // 开户银行         
	      String baddr           =(String) request.getParameter("baddr");  //开户银行地址         
	      String bno1            =(String) request.getParameter("bno1");   //第二开户银行         
	      String baddr1          =(String) request.getParameter("baddr1");  // 第二开户银行地       
	      String accno1          =(String) request.getParameter("accno1");// 第二银行帐号         
	      String companyaddress =(String) request.getParameter("companyaddress");// 总公司地址
  
	      String cwno            =(String) request.getParameter("cwno");     // 财务编号  
	      String cwname          =(String) request.getParameter("cwname");   // 财务名称
	      String cwzone          =(String) request.getParameter("cwzone");   // 财务地区
	      String cwjzdate        =(String) request.getParameter("cwjzdate"); // 财务结帐日期
	      String cwjzcredit      =(String) request.getParameter("cwjzcredit"); //财务应收款 		     
	      String jzperiod        =(String) request.getParameter("jzperiod");  // 结帐周期 	
	      String credit          =(String) request.getParameter("credit");    //信用额度 			     
//其他信息		     
	      String paykind         =(String) request.getParameter("paykind"); //选择支付方式    
	      String title           =(String) request.getParameter("title"); // 发票标题  
	      String assess          =(String) request.getParameter("assess");  // 考察评估意见  
	      String remark          =(String) request.getParameter("remark"); //备注         
	      String fancy           =(String) request.getParameter("fancy");   //老板的文化程度      
	      String cregrade        =(String) request.getParameter("cregrade");   //信用额度等级 			     
	      String clikind         =(String) request.getParameter("clikind"); // 选择客户等级  		     
	      String country         =(String) request.getParameter("country");    // 国家
	      String province        =(String) request.getParameter("province");   //省份 
	      String county          =(String) request.getParameter("county");     // 县市
	      String states          =(String) request.getParameter("states");     // 乡
	      String status          =(String) request.getParameter("status'");    // 村		     
	      String postalcode     =(String) request.getParameter("postalcode");//邮编 		
	      String idt_person     =(String) request.getParameter("idt_person");        //业务员ID
		     
	    //客户信息头
			accountcode        =(accountcode    !=null)? accountcode     :"0";              
			accountname        =(accountname    !=null)? accountname     :"0";         
			corporator         =(corporator     !=null)? corporator      :"0";         
			linkertel          =(linkertel      !=null)? linkertel       :"0";         
	//企业信息       
			customercode       =(customercode   !=null)? customercode    :"0";         
			customername       =(customername   !=null)? customername    :"0";         
			corporatorcode     =(corporatorcode !=null)? corporatorcode  :"0";         
			addresscop         =(addresscop     !=null)? addresscop      :"0";         
			addresssale        =(addresssale    !=null)? addresssale     :"0";         
			addressstock       =(addressstock   !=null)? addressstock    :"0";         
			addresstran        =(addresstran    !=null)? addresstran     :"0";         
			linker             =(linker         !=null)? linker          :"0";         
			linkermobile       =(linkermobile   !=null)? linkermobile    :"0";         
			linkerfax          =(linkerfax      !=null)? linkerfax       :"0";         
			email              =(email          !=null)? email           :"0";         
			product            =(product        !=null)? product         :"0";         
			creevaluate        =(creevaluate    !=null)? creevaluate     :"0";         
			kind               =(kind           !=null)? kind            :"0";         
			regmoney           =(regmoney       !=null)? regmoney        :"0";         
			scope              =(scope          !=null)? scope           :"0";         
	//财务信息       
			taxno              =(taxno          !=null)? taxno           :"0";         
			accno              =(accno          !=null)? accno           :"0";         
			bno                =(bno            !=null)? bno             :"0";         
			baddr              =(baddr          !=null)? baddr           :"0";         
			bno1               =(bno1           !=null)? bno1            :"0";         
			baddr1             =(baddr1         !=null)? baddr1          :"0";         
			accno1             =(accno1         !=null)? accno1          :"0";         
			companyaddress     =(companyaddress !=null)? companyaddress  :"0";         
			cwno               =(cwno           !=null)? cwno            :"0";         
			cwname             =(cwname         !=null)? cwname          :"0";         
			cwzone             =(cwzone         !=null)? cwzone          :"0";         
			cwjzdate           =(cwjzdate       !=null)? cwjzdate        :"2008-10-10";         
			cwjzcredit         =(cwjzcredit     !=null)? cwjzcredit      :"0";         
			jzperiod           =(jzperiod       !=null)? jzperiod        :"0";         
			credit             =(credit         !=null)? credit          :"0";         
	//其他信息         
			paykind            =(paykind        !=null)? paykind         :"0";         
			title              =(title          !=null)? title           :"0";         
			assess             =(assess         !=null)? assess          :"0";         
			remark             =(remark         !=null)? remark          :"0";         
			fancy              =(fancy          !=null)? fancy           :"0";         
			cregrade           =(cregrade       !=null)? cregrade        :"0";         
			clikind            =(clikind        !=null)? clikind         :"0";         
			country            =(country        !=null)? country         :"0";         
			province           =(province       !=null)? province        :"0";         
			county             =(county         !=null)? county          :"0";         
			states             =(states         !=null)? states          :"0";         
			status             =(status         !=null)? status          :"0";         
			postalcode         =(postalcode     !=null)? postalcode      :"0";         
			idt_person                =(idt_person            !=null)? idt_person             :"0";
			
	      System.out.println("accountcode="+accountcode);
	      System.out.println("accountname="+accountname);
	      System.out.println("corporator="+corporator);
	      System.out.println("linkertel="+linkertel);
	      System.out.println("customercode="+customercode);
	      System.out.println("customername="+customername);
	      System.out.println("corporatorcode="+corporatorcode);
	      System.out.println("addresscop="+addresscop);
	      System.out.println("addresssale="+addresssale);
	      System.out.println("addressstock="+addressstock);
	      System.out.println("addresstran="+addresstran);
	      System.out.println("linker="+linker);
	      System.out.println("linkermobile="+linkermobile);
	      System.out.println("linkerfax="+linkerfax);
	      System.out.println("email="+email);
	      System.out.println("product="+product);
	      System.out.println("creevaluate="+creevaluate);
	      System.out.println("kind="+kind);
	      System.out.println("regmoney="+regmoney);
	      System.out.println("scope="+scope);
	      System.out.println("taxno="+taxno);
	      System.out.println("accno="+accno);
	      System.out.println("bno="+bno);
	      System.out.println("baddr="+baddr);
	      System.out.println("bno1="+bno1);
	      System.out.println("baddr1="+baddr1);
	      System.out.println("accno1="+accno1);
	      System.out.println("companyaddress="+companyaddress);
	      System.out.println("cwno="+cwno);
	      System.out.println("cwname="+cwname);
	      System.out.println("cwzone="+cwzone);
	      System.out.println("cwjzdate="+cwjzdate);
	      System.out.println("cwjzcredit="+cwjzcredit);
	      System.out.println("jzperiod="+jzperiod);
	      System.out.println("credit="+credit);
	      System.out.println("paykind="+paykind);
	      System.out.println("title="+title);
	      System.out.println("assess="+assess);
	      System.out.println("remark="+remark);
	      System.out.println("fancy="+fancy);
	      System.out.println("cregrade="+cregrade);
	      System.out.println("clikind="+clikind);
	      System.out.println("country="+country);
	      System.out.println("province="+province);
	      System.out.println("county="+county);
	      System.out.println("states="+states);
	      System.out.println("status="+status);
	      System.out.println("postalcode="+postalcode);
	      System.out.println("pid&idt_person ="+idt_person);

		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		boolean success = false;
		String message = "";
		TClient u = new TClient();
		//客户头 
        u.setAccountcode(accountcode);
        u.setAccountname(accountname); 
        u.setCorporator(corporator); 
        u.setLinkertel(linkertel);
//企业信息u.set  
        u.setCustomercode(customercode);
        u.setCustomername(customername);
        u.setCorporatorcode(corporatorcode);
	    u.setAddresscop(addresscop);
	    u.setAddresssale(addresssale);
	    u.setAddressstock(addressstock);
	    u.setAddresstran(addresstran);
        u.setLinker(linker);
        u.setLinkermobile(linkermobile);
        u.setLinkerfax(linkerfax);
        u.setEmail(email);
        u.setProduct(product);
        u.setCreevaluate(creevaluate);
        u.setKind(kind);
        u.setRegmoney(regmoney);
        u.setScope(scope);
//财务信息u.set 
        u.setTaxno(taxno);
        u.setAccno(accno);
        u.setBno(bno);
        u.setBaddr(baddr);
        u.setBno1 (bno1);
	    u.setBaddr1(baddr1);
        u.setAccno1(accno1);
	    u.setCompanyaddress(companyaddress);
	    u.setCwno(cwno);
	    u.setCwname(cwname);
	    u.setCwzone(cwzone);
	    u.setCwjzdate(cwjzdate=(cwjzdate==""?null:cwjzdate));
	    u.setCwjzcredit (cwjzcredit=(cwjzcredit==""?null:cwjzcredit));
	    u.setJzperiod (Integer.parseInt(jzperiod));
	    try{
	    	u.setCredit(new BigDecimal(credit));
	    }catch(Exception e){}
//其他信息                                           
	    u.setPaykind         (paykind);
	    u.setTitle           (title);
	    u.setAssess          (assess);
	    u.setRemark          (remark);
	    u.setFancy           (fancy);
	    u.setCregrade        (cregrade=cregrade==""?"0":cregrade);
	    u.setClikind         (clikind);
	    u.setCountry         (country);
	    u.setProvince        (province);
	    u.setCounty          (county);
	    u.setStates          (states);
	    u.setStatus          (status);
	    u.setPostalcode     (postalcode);
	    try{
	    	u.setPid(Integer.parseInt(idt_person));
	    }catch(Exception e){}
		int i = getCcamsService().getTclientDao().addClient(u);
		
		
		if (i == 1) {
			success = true;
			message = "用户添加成功";
		} else {
			success = false;
			message = "用户添加失败";
		}
		jsonMap.put("success", success);
		jsonMap.put("message", message);
		json.putAll(jsonMap);
	}
}
